//
//  AttentionViewController.m
//  iOS-CtrlV
//
//  Created by Wang Li on 12-12-19.
//  Copyright (c) 2012年 Wang Li. All rights reserved.
//

#import "AttentionViewController.h"
#import "ASIFormDataRequest.h"
#import "MainTabBarController.h"
#import "CJSONDeserializer.h"
#define MaxPageNum [NSNumber numberWithInt:10]

@interface AttentionViewController ()

@end

@implementation AttentionViewController
@synthesize m_NeedFirstDataRequest;
@synthesize m_HaveRequest;
- (id)init
{
    if (self = [super init]) {
        // Custom initialization
        m_HaveRequest =NO;
        self.m_NowModeType = Mode_Type_Attention;
    }
    return self;
}

-(void) dealloc
{
    [_TShowTitleView release];
    [_SearchBttBarItem release];
    [super dealloc];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor colorWithRed:204/255.f green:204/255.f blue:204/255.f alpha:1]];
    
     AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    if([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
        [self.navigationController.navigationBar setBackgroundImage:tAppDel.m_LeftNavImg forBarMetrics: UIBarMetricsDefault];
        self.navigationController.navigationBar.clipsToBounds = NO;
        

    }
    
    _SearchBttBarItem = [UIButton buttonWithType:UIButtonTypeCustom];
    _SearchBttBarItem.frame =CGRectMake(320-44, 0, 44, 44);
    [_SearchBttBarItem setImage:[UIImage imageNamed:@"navsearch.png"] forState:UIControlStateNormal];
    [_SearchBttBarItem addTarget:self action:@selector(startSearchView) forControlEvents:UIControlEventTouchUpInside];
    [_SearchBttBarItem retain];
    [self.navigationController.navigationBar addSubview:_SearchBttBarItem];
}


-(void) viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [_SearchBttBarItem removeFromSuperview];
}

-(void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    // Do any additional setup after loading the view.
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    if([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
        [self.navigationController.navigationBar setBackgroundImage:tAppDel.m_LeftNavImg forBarMetrics: UIBarMetricsDefault];
        self.navigationController.navigationBar.clipsToBounds = NO;
    }
    if ([self.navigationController.navigationBar viewWithTag:0x300] == nil) {
        UIImageView* tImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navshadow.png"]];
        tImgView.tag =0x300;
        tImgView.frame =CGRectMake(0, 44, 320, 5);
        [self.navigationController.navigationBar addSubview:tImgView];
        [tImgView release];
    }

    if (_PopToRootBtt == nil) {
        _PopToRootBtt =[UIButton buttonWithType:UIButtonTypeCustom];
        _PopToRootBtt.frame =CGRectMake(120, 0, 80, 44);
        [_PopToRootBtt addTarget:self action:@selector(popToRoot) forControlEvents:UIControlEventTouchUpInside];
        [_PopToRootBtt retain];
        [self.navigationController.navigationBar addSubview:_PopToRootBtt];
    }
    if ([_SearchBttBarItem superview] ==nil) {
        [self.navigationController.navigationBar addSubview:_SearchBttBarItem];
    }
    MainTabBarController* tMainTabBar = (MainTabBarController*)self.navigationController.tabBarController;
    [tMainTabBar.m_TabbarCustom removeFromSuperview];
    tMainTabBar.m_TabbarCustom.hidden =NO;
    [self.view addSubview:tMainTabBar.m_TabbarCustom];
    //if (m_NeedFirstDataRequest && !m_HaveRequest) {
        self.m_RquestURL = [NSString stringWithFormat:@"%@?app=blog&act=followList&user_id=%@",RequestMainURL,[tMainTabBar.m_UserDic objectForKey:@"user_id"]];
        m_HaveRequest=YES;
        [_TShowTitleView removeFromSuperview];
        _TShowTitleView = nil;
        [self firstDataGet];
    //}
}

-(void) ShowTipView
{
    _NowPageIndex --;
    
    [self CreatetitelView:@"     暂无关注对象" rect:CGRectMake(0,0,320,480-20-44-49)];
}

- (void)CreatetitelView:(NSString*)str rect:(CGRect)_rect
{
    if (_TShowTitleView == nil) {
        _TShowTitleView = [[UIView alloc] initWithFrame:_rect];
        [_TShowTitleView setBackgroundColor:[UIColor clearColor]];
        CGSize iSize  = [str sizeWithFont:[UIFont systemFontOfSize:24.0f]];
        NSInteger x =65;// (m_title.frame.size.width-iSize.width)/2;
        NSInteger y = (_TShowTitleView.frame.size.height-iSize.height)/2-24;
        UILabel* name = [[UILabel alloc] initWithFrame:CGRectMake(x, y,200, 60)];
        name.tag = 101;
        name.backgroundColor = [UIColor clearColor];
        name.font = [UIFont boldSystemFontOfSize:24.f];
        name.textColor = [UIColor colorWithRed:128.0/255.0f green:128.0/255.0f blue:128.0/255.0f alpha:1.0f];
        name.text = str;
        name.shadowColor = [UIColor colorWithRed:230/255.0f green:230/255.0f blue:230/255.0f alpha:1.0f];
        name.shadowOffset = CGSizeMake(0, 1);
        name.numberOfLines = 0;
        [_TShowTitleView addSubview:name];
        [name release];
        [self.view addSubview:_TShowTitleView];
        [self.view sendSubviewToBack:_TShowTitleView];
    }
}

-(void) popToRoot
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

-(void) startSearchView
{
    _searchStatus = !_searchStatus;
    if (_searchStatus) {
        [self showSearchView];
    }else{
        [self dissSearchView];
    }
}

-(void) AttDissSearch
{
    _searchStatus =NO;
    [self dissSearchView];
}


@end
